
const GHRegularType = {
  lang: 'zh',
  email: 'email',
  url: 'url',
  phone: 'phone',
  idcard: 'idcard'
};

class GHRegular {
  constructor() { }
  static match(type, str) {
    let reg = ''
    if (type === GHRegularType.lang) { 
      // 匹配中文字符
      reg = /[\u4e00-\u9fa5]/;
    } else if (type === GHRegularType.email) { 
      // 匹配email地址
      reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    } else if (type === GHRegularType.url) { 
      // 匹配URL地址
      reg = /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9_-](\?)?)*)*$/i;
    } else if (type === GHRegularType.phone) { 
      // 匹配手机号码
      reg = /^(0|86|17951)?(13[0-9]|14[579]|15[012356789]|16[56]|17[1235678]|18[0-9]|19[89])\s{0,1}[0-9]{4}\s{0,1}[0-9]{4}$/;
    } else if (type === GHRegularType.idcard) { 
      // 匹配身份证号
      reg = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
    } else if (type === GHRegularType.email) { 
      // 匹配邮编号
      reg = /^[1-9]\d{5}(?!\d)$/;
    }
    return reg.test(str);
  }
}

export {
  GHRegularType,
  GHRegular
};
